// 菜单管理接口
import request from '@/utils/request'
import type { MenuResData } from './menuType'

enum API {
  all_menu = '/api/menu/page',
  add_menu = '/api/menu/add',
  update_menu = '/api/menu/update',
  delete_menu = '/api/menu/delete',
}
// 获取菜单列表
export const reqAllMenu = (menuName?:string) => {
  const url = `${API.all_menu}${menuName ? `?menuName=${menuName}` : ''}`
  return request.get<any, MenuResData>(url)
}
// 新增菜单、编辑菜单
export const reqAddOrUpdateMenu = (data: any) => {
  if (data.id) {
    return request.put<any,any>(API.update_menu, data)
  } else {
    return request.post<any,any>(API.add_menu, data)
  }
}
// 删除单个菜单
export const reqRemoveMenu = (id: number, version:number) => {
  return request.delete<any,any>(API.delete_menu + `?id=${id}&version=${version}`)
}
